﻿using CP.Utility;
using GPM;
using LF3.Controllers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LF3Proj
{
    public partial class FrmLog : BaseForm
    {
        public FrmLog()
        {
            InitializeComponent();
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            if ((string.IsNullOrEmpty(this.lkupHeatid.Text)) && (this.dtStart.EditValue == null) && (this.dtEnd.EditValue == null))
            {
                ExMessageBox.Show("查询条件不能为空", AppSetter.SoftName);
                return;
            }

            if (string.IsNullOrEmpty(this.lkupHeatid.Text))
            {
                if (this.dtStart.EditValue == null)
                {
                    ExMessageBox.Show("开始时间不能为空", AppSetter.SoftName);
                    return;
                }

                if (this.dtEnd.EditValue != null)
                {
                    if (Convert.ToDateTime(this.dtEnd.EditValue) < Convert.ToDateTime(this.dtStart.EditValue))
                    {
                        ExMessageBox.Show("结束时间必须大于等于开始时间", AppSetter.SoftName);
                        return;
                    }
                }
            }
            string heatid = "";
            string start = "";
            string end = "";

            if (string.IsNullOrEmpty(this.lkupHeatid.Text))
                heatid = this.lkupHeatid.Text;
            if (this.dtStart.EditValue != null)
                start = Convert.ToDateTime(this.dtStart.EditValue).ToString("yyyy-MM-dd");
            if (this.dtEnd.EditValue != null)
                end = Convert.ToDateTime(this.dtEnd.EditValue).ToString("yyyy-MM-dd");

            Operate_LogController ctl = new Operate_LogController();
            this.gcOperateLog.DataSource = ctl.GetOperateLogCondition(heatid, start, end);
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if ((string.IsNullOrEmpty(this.txtHeatid.Text)) && (this.dtDate1.EditValue == null) && (this.dtDate2.EditValue == null))
            {
                ExMessageBox.Show("查询条件不能为空", AppSetter.SoftName);
                return;
            }

            if (string.IsNullOrEmpty(this.txtHeatid.Text))
            {
                if (this.dtDate1.EditValue == null)
                {
                    ExMessageBox.Show("开始时间不能为空", AppSetter.SoftName);
                    return;
                }

                if (this.dtDate2.EditValue != null)
                {
                    if (Convert.ToDateTime(this.dtDate2.EditValue) < Convert.ToDateTime(this.dtDate1.EditValue))
                    {
                        ExMessageBox.Show("结束时间必须大于等于开始时间", AppSetter.SoftName);
                        return;
                    }
                }
            }
            string heatid = "";
            string start = "";
            string end = "";

            if (string.IsNullOrEmpty(this.txtHeatid.Text))
                heatid = this.txtHeatid.Text;
            if (this.dtDate1.EditValue != null)
                start = Convert.ToDateTime(this.dtDate1.EditValue).ToString("yyyy-MM-dd");
            if (this.dtDate2.EditValue != null)
                end = Convert.ToDateTime(this.dtDate2.EditValue).ToString("yyyy-MM-dd");

            Operate_LogController ctl = new Operate_LogController();
            this.gridControl1.DataSource = ctl.GetHeatEventCondition(heatid, start, end);
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            if ((this.dateEdit1.EditValue == null) && (this.dateEdit2.EditValue == null))
            {
                ExMessageBox.Show("查询条件不能为空", AppSetter.SoftName);
                return;
            }

            if (this.dateEdit1.EditValue == null)
            {
                ExMessageBox.Show("开始时间不能为空", AppSetter.SoftName);
                return;
            }

            if (this.dateEdit2.EditValue != null)
            {
                if (Convert.ToDateTime(this.dateEdit2.EditValue) < Convert.ToDateTime(this.dateEdit1.EditValue))
                {
                    ExMessageBox.Show("结束时间必须大于等于开始时间", AppSetter.SoftName);
                    return;
                }
            }
             
            string start = "";
            string end = "";
             
            if (this.dtDate1.EditValue != null)
                start = Convert.ToDateTime(this.dtDate1.EditValue).ToString("yyyy-MM-dd");
            if (this.dtDate2.EditValue != null)
                end = Convert.ToDateTime(this.dtDate2.EditValue).ToString("yyyy-MM-dd");

            Operate_LogController ctl = new Operate_LogController();
            this.gridControl2.DataSource = ctl.GetPlcMatCondition(start, end);
        }

        private void FrmLog_Load(object sender, EventArgs e)
        {
            Operate_LogController ctl = new Operate_LogController();
            this.repositoryItemLookUpEdit7.DataSource = ctl.GetAllCode();
        }
    }
}
